<?php


namespace app\admin\model;


use think\Model;

/**
 * Class HtnsUser
 * @package app\admin\model
 * @desc 海淘女神-用户
 */
class HtnsUser extends Model
{
    protected $connection = 'htns';
    protected $table = 'eb_user';
    protected $pk = 'uid';// 主键
    // 代理等级
    public $gradeLevel = [
        1 => 'VIP',
        2 => '社群合伙人',
        3 => '社群节点',
        4 => '联盟节点',
    ];

    // 获取代理等级名称
    public function getGradeName($gradeId)
    {
        $name = '普通用户';
        if ($gradeId) {
            $name = $this->gradeLevel[$gradeId];
        }
        return $name;
    }

    // 获取有效用户数
    public function getUserNum($storeId = 0)
    {
        $where['status'] = 1;
        $where['is_del'] = 0;
        if($storeId){
            $where['store_id'] = $storeId;
        }
        $res = self::where($where)->count();
        return $res;
    }
    // 获取用户列表
    public static function getUserList($where = [])
    {
        $where[] = ['is_del' , '=' , 0];
        $where[] = ['status' , '=' , 1];
        $users = self::where($where)->order('uid desc')->select()->toArray();
        foreach ($users as &$v) {
            $v['user_info'] = sprintf('%s-%s-%s-%s',$v['uid'],$v['phone'],$v['nickname'],$v['real_name']);
        }
        return $users;
    }
}